<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ShopGoods extends Model
{
    use HasFactory;

    protected $table = 'sp_shop_goods';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //status状态1 启用  0禁用
    const SHOP_GOODS_STATUS_ENABLE = 1;//启用
    const SHOP_GOODS_STATUS_DISABLE = 0;//禁用

    //is_delete是否删除 0未删除  1已删除
    const SHOP_GOODS_IS_DELETE = 1;//已删除
    const SHOP_GOODS_NOT_DELETE = 0;//未删除

    //店铺关联商品列表
    protected function GetShopGoodsList($pageSize, $where)
    {
        $select = array('sg.id', 'sg.member_id', 'sg.sort', 'sg.create_time', 'sg.status', 'sc.cat_name', 'g.title', 'g.imgurl');
        $data = $this
            ->from('sp_shop_goods as sg')
            ->leftjoin('sp_shop_category as sc', 'sc.id', 'sg.cat_id')
            ->leftjoin('sp_goods_2 as g', 'g.id', 'sg.goods_id')
            ->select($select)
            ->where($where)
            ->orderBy('sg.sort', 'asc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }

}
